package cn.edu.sdjzu.xg23.kcsj01_backend.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@JsonIgnoreProperties({"handler", "lazyLoader"})
public class User {
    private Long id;
    private String username;//用户名
    private String password;//密码
    private ActorType actorType;  //记录关联的实际参与者，比如教师还是学生
    private LocalDateTime lastLoginTime; //登录时间
    private String createTime; //创建时间


    @JsonTypeInfo(
            use = JsonTypeInfo.Id.NAME,
            include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
            property = "actorType" // 根据 actorType 字段的值决定实例化哪个子类
    )
    @JsonSubTypes({
            @JsonSubTypes.Type(value = Employee.class, name = "TEACHER"),
//            @JsonSubTypes.Type(value = Student.class, name = "STUDENT") // 如果有其他实现类
    })
    private Actor actor; //关联的实际参与者对象，为Actor的某一个子类的对象

    public User(Long id) {
        this.id = id;
    }
}
